package com.itheima.ydd.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.ydd.config.R;
import com.itheima.ydd.dto.PageDto;
import com.itheima.ydd.dto.SysRoleDto;
import com.itheima.ydd.entity.SysRole;
import com.itheima.ydd.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/sys_role")
public class SysRoleController {

    @Autowired
    private ISysRoleService roleService;

    @GetMapping("/allData")
    public R<List> allDta(){
        LambdaQueryWrapper<SysRole> roleLambdaQueryWrapper = new LambdaQueryWrapper<>();
     /*   roleLambdaQueryWrapper.eq(SysRole::getDelFlag,"0");
*/
        roleLambdaQueryWrapper.orderByDesc(SysRole::getCreateDate);
        List<SysRole> sysRoles = roleService.list(roleLambdaQueryWrapper);

        return R.success(sysRoles);

    }

    /**
     * 分页
     * @param name
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
    public R<PageDto> list(String name,int page, int limit ){
        PageDto pageDto= roleService.getList(name,page,limit);
        return R.success(pageDto);
    }

    /**
     * 新增
     * @param map
     * @return
     */
    @PostMapping("/add")
    public R<String>add(@RequestBody Map<String ,Object>map){
        roleService.add(map);
        return R.success("添加成功");
    }


    /**
     * 修改回显
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public R<SysRoleDto>rowInfo(String id){
        SysRoleDto sysRoleDto= roleService.rowInfo(id);
        return R.success(sysRoleDto);
    }

    /**
     * 角色修改
     * @param sysRoleDto
     * @return
     */
    @PostMapping("/update")
    public R<String>update(@RequestBody SysRoleDto sysRoleDto){
        roleService.updateRole(sysRoleDto);
        return R.success("修改成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    public R<String>del(String id){
        roleService.del(id);
        return R.success("删除成功");
    }



}
